﻿/*****************************************************************
 *@Copyright all rights reserved © 2014 Yuga
 *@author Oplink OMS
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webbase.modules.sys.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

import com.oplink.webbase.common.persistence.BaseDao;
import com.oplink.webbase.common.persistence.BaseDaoImpl;
import com.oplink.webbase.modules.sys.entity.Config;
import com.oplink.webbase.modules.sys.entity.Dict;

/**
 * 告警DAO接口
 * 
 * @author Oplink OMS
 * @version 2014-09-03
 */
public interface ConfigDao extends ConfigDaoCustom, CrudRepository<Config, Long> {

	@Modifying
	@Query("update Config set delFlag='" + Config.DEL_FLAG_DELETE + "' where id = ?1")
	public int deleteById(Long id);

	@Query("from Config where delFlag='" + Dict.DEL_FLAG_NORMAL + "' AND user.id = ?1 ORDER BY sort")
	public List<Config> findAllListById(Long id);

	@Query("from Config where delFlag='" + Dict.DEL_FLAG_NORMAL
			+ "' AND user.id = ?1 AND catalog=?2 ORDER BY parentIds")
	public List<Config> findAllListById(Long id, String catalog);

	@Query("from Config where delFlag='" + Dict.DEL_FLAG_NORMAL + "' AND user.id = ?1 AND catalog=?2 ORDER BY sort")
	public List<Config> findAllListByIdSort(Long id, String catalog);
}

/**
 * DAO自定义接口
 * 
 * @author Oplink OMS
 */
interface ConfigDaoCustom extends BaseDao<Config> {

}

/**
 * DAO自定义接口实现
 * 
 * @author Oplink OMS
 */
@Component
class ConfigDaoImpl extends BaseDaoImpl<Config> implements ConfigDaoCustom {

}